import org.openqa.selenium.By;

import java.io.IOException;

/**
 * @projectName: The-examination-questionnaire-pass-test
 * @package: PACKAGE_NAME
 * @className: RegisterPage
 * @author: Tongxinxin
 * @description: 注册界面测试
 * @date: 2025/9/22 0:27
 * @version: 1.0
 */
public class RegisterPage extends Util{
    public static String url="http://8.155.1.153:8081/user/register";

    public RegisterPage() {
        super(url);
    }

    //检查页面能否正常打开
    public void Register(){
        //检查是否有注册按钮
        driver.findElement(By.cssSelector("#root > div > div.content___1k5Ro > div.main___19HXK > div > form > button"));
        //点击输入框
        driver.findElement(By.cssSelector("#name"));
    }
    //注册成功
    public void RegisterSuc() throws IOException {
        driver.findElement(By.cssSelector("#name")).sendKeys("qweqwe");
        driver.findElement(By.cssSelector("#username")).sendKeys("qweqwe");
        driver.findElement(By.cssSelector("#password")).sendKeys("123123");
        driver.findElement(By.cssSelector("#rePassword")).sendKeys("123123");
        driver.findElement(By.cssSelector("#root > div > div.content___1k5Ro > div.main___19HXK > div > form > button > span")).click();
        //检查弹窗是否注册成功并跳转至登录界面
        driver.findElement(By.cssSelector("#root > div > div.content___2zk1- > div.top___1C1Zi > div.header___5xZ3f > span"));
        String regi = driver.getTitle();
        getScreenShot(getClass().getName());
        assert regi.equals("问卷考试系统");
    }
    //注册失败--不输入用户名，其他正常输入
    public void RegisterFail1() throws IOException {
        driver.findElement(By.cssSelector("#username")).sendKeys("qweqwe");
        driver.findElement(By.cssSelector("#password")).sendKeys("123123");
        driver.findElement(By.cssSelector("#rePassword")).sendKeys("123123");
        driver.findElement(By.cssSelector("#root > div > div.content___1k5Ro > div.main___19HXK > div > form > button > span")).click();
        //检查是否注册失败并弹出提示
        driver.findElement(By.cssSelector("#name_help > div"));
        String regi=driver.getTitle();
        getScreenShot(getClass().getName());
        assert regi.equals("用户名是必填项");
    }

    //注册失败--输入已经注册过的账户
    public void RegisterFail2() throws IOException {
        driver.findElement(By.cssSelector("#name")).sendKeys("abcabc");
        driver.findElement(By.cssSelector("#username")).sendKeys("abcabc");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#rePassword")).sendKeys("123456");
        driver.findElement(By.cssSelector("#root > div > div.content___1k5Ro > div.main___19HXK > div > form > button > span")).click();
        //检查弹窗是否注册成功并跳转至登录界面
        driver.findElement(By.cssSelector("#root > div > div.content___1k5Ro > div.main___19HXK > div > form > div.ant-alert.ant-alert-error > div > div"));
        String regi=driver.getTitle();
        getScreenShot(getClass().getName());
        assert regi.equals("账号已存在");
    }

    //注册失败--确认密码和密码不一致
    public void RegisterFail3() throws IOException {
        driver.findElement(By.cssSelector("#name")).sendKeys("qweqwe");
        driver.findElement(By.cssSelector("#username")).sendKeys("qweqwe");
        driver.findElement(By.cssSelector("#password")).sendKeys("123123");
        driver.findElement(By.cssSelector("#rePassword")).sendKeys("123456789");
        driver.findElement(By.cssSelector("#root > div > div.content___1k5Ro > div.main___19HXK > div > form > button > span")).click();
        //检查弹窗是否注册成功并跳转至登录界面
        driver.findElement(By.cssSelector("#rePassword_help > div"));
        String regi=driver.getTitle();
        getScreenShot(getClass().getName());
        assert regi.equals("两次密码不一致");
    }
}
